home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / ibmchars < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  5.4 KB  |  184 lines

  1. #!/bin/ksh
  2. # ibmchars: print ibm graphic characters for reference.
  3. # @(#) ibmchars.ksh 1.1 94/05/09
  4. # 92/01/26 john h. dubois iii (john@armory.com)
  5. # 92/09/15 Converted from boxchars into ibmchars.
  6. # 92/10/17 Added 'low', 'high', and 'all' options.
  7. # 94/05/09 Added v option, expanded help.
  8.  
  9. # Usage: PrintChar <format> <charnum> <char>
  10. # Shows the value <charnum> in various bases according to <format>,
  11. # then prints the string <char>
  12. function PrintChar {
  13.     typeset Format=$1 out=
  14.     typeset -i fwidth value=$2
  15.  
  16.     while [ -n "$Format" ]; do
  17.     case $Format in
  18.     d*)
  19.         typeset -R3 dec=$value
  20.         out="$out$dec "
  21.         ;;
  22.     [oO]*)
  23.         typeset -i8 octal=$value
  24.         typeset -Z3 o3=${octal#8#}
  25.         [[ $Format = O* ]] && out="${out}0"
  26.         out="$out$o3 "
  27.         ;;
  28.     [xX]*)
  29.         typeset -i16 hex=$value
  30.         typeset x2=${hex#16#}
  31.         # Can't use -Z2 because hex chars may not be digits
  32.         [[ ${#x2} -lt 2 ]] && x2=0$x2
  33.         [[ $Format = X* ]] && x2=0x$x2
  34.         out="$out$x2 "
  35.         ;;
  36.     esac
  37.     Format=${Format#?}
  38.     done
  39.     let fwidth=${#out}+3
  40.     let printcount+=fwidth
  41.     if [ printcount -gt width ]; then
  42.     echo ""
  43.     printcount=fwidth
  44.     fi
  45.     echo -n "$out$3  "
  46. }
  47.  
  48. function PrintBox {
  49.     for box in ascii ibm1 ibm2; do
  50.     # Select box drawing characters.
  51.     # t, b, l, r: used where a bar joins with the outer 
  52.     # {top, left, bottom, right} bar of the box.
  53.     # tl, bl, tr, br: used for the
  54.     # {top left, bottom left, top right, bottom right} corner of the box.
  55.     # m: middle; used where a horizontal and vertical bar cross each other.
  56.     # h, v: used for drawing {horizontal, vertical} bars.
  57.     case $box in
  58.     ascii) t="\0055" b="\0055" l="\0174" r="\0174" tl="\0055" bl="\0055"
  59.           tr="\0055" br="\0055" m="\0053" h="\0055" v="\0174";;
  60.     ibm2) t="\0313" b="\0312" l="\0314" r="\0271" tl="\0311" bl="\0310"
  61.           tr="\0273" br="\0274" m="\0316" h="\0315" v="\0272";;
  62.     ibm1) t="\0302" b="\0301" l="\0303" r="\0264" tl="\0332" bl="\0300"
  63.           tr="\0277" br="\0331" m="\0305" h="\0304" v="\0263";;
  64.     esac
  65.  
  66.     echo -n "
  67. $tl$h$t$h$tr        ${tl#\\} $tl ${h#\\} $h ${t#\\} $t ${h#\\} $h ${tr#\\} $tr
  68. $v $v $v        ${v#\\} $v        ${v#\\} $v        ${v#\\} $v
  69. $l$h$m$h$r        ${l#\\} $l ${h#\\} $h ${m#\\} $m ${h#\\} $h ${r#\\} $r
  70. $v $v $v        ${v#\\} $v        ${v#\\} $v        ${v#\\} $v
  71. $bl$h$b$h$br        ${bl#\\} $bl ${h#\\} $h ${b#\\} $b ${h#\\} $h ${br#\\} $br"
  72.     done
  73.     echo ""
  74. }
  75.  
  76. function PrintAll {
  77.     typeset -i i=0
  78.     while [ i -lt 32 ]; do
  79.     PrintChar $Format $i `echo "\033[${i}g"`
  80.     let i+=1
  81.     done
  82.     i=127
  83.     while [ i -lt 256 ]; do
  84.     PrintChar $Format $i `echo "\033[${i}g"`
  85.     let i+=1
  86.     done
  87.     echo ""
  88. }
  89.  
  90.  
  91. function PrintHigh {
  92.     typeset -i count=127 endcount=255
  93.     typeset -i8 oct
  94.  
  95.     while [ count -le endcount ]; do
  96.     oct=count
  97.     if [ count -eq 155 ]; then
  98.         PrintChar $Format $count ' '
  99.     else
  100.         PrintChar $Format $count `echo "\0${oct#8#}"`
  101.     fi
  102.     let count+=1
  103.     done
  104.     echo ""
  105. }
  106.  
  107. name=${0##*/}
  108. Usage="Usage: $name [-h] [-f filename] ..."
  109. typeset -i width=${COLUMNS:-79}-1    # Max column to print to
  110. typeset -i printcount=0            # Column counter
  111. Usage="Usage: $name [-h] [-v[doOxX-]] [box|all|high ...]"
  112. Format=do
  113.  
  114. while getopts :hv: opt; do
  115.     case $opt in
  116.     h) echo \
  117. "$name: print IBM graphics characters for reference.
  118. $Usage
  119. high: Prints the high (127..255) characters directly.  This is the default
  120.       display.  Requires an 8-bit-clean connection.  This will work with any
  121.       device (printer, terminal, etc.) that uses the IBM character set if it
  122.       has an 8-bit connection.  Other devices will display characters from
  123.       their native set.  The high-escape character (escape+128, character 155)
  124.       is displayed as a space because the SCO console interprets it as an
  125.       escape character.
  126. all:  Print the low (0..31) and high (127..255) characters.  Character 155 is
  127.       displayed correctly.  The SCO console alternate-font escape sequence is
  128.       used to print both low and high characters.  This does not actually
  129.       switch hardware fonts; it lets characters be printed by decimal value. 
  130.       This allows the printing of characters whose ASCII values are normally
  131.       mapped to control characters, and the printing of characters with high
  132.       values (>127) that are not printable without an 8-bit-clean connection.
  133. box:  Draws boxes using ascii, ibm1, and ibm2 characters.
  134.       Next to each box structure, a similar box structure is drawn
  135.       with the octal value of each character printed next to it.
  136. Options:
  137. -h: Print this help.
  138. -v[doOxX-]: Set the format in which the value of each character is printed for
  139.     the high & low character sets.  The value precedes each character.
  140.     o and O print the value in octal without and with a leading 0.
  141.     x and X print the value in hex without and with a leading 0x.
  142.     d prints the value in decimal.  - prints no value.  The default is -vdo."
  143.        exit 0
  144.        ;;
  145.     v)
  146.     Format=$OPTARG
  147.     if [[ "$Format" != +([-doOxX]) ]]; then
  148.         print -u2 "Bad format given with -v.  Use -h for help."
  149.         exit 1
  150.     fi
  151.     ;;
  152.     +?)
  153.     echo "$name: options should not be preceded by a '+'."
  154.     exit 1
  155.     ;;
  156.     :) 
  157.     print -r -u2 -- \
  158.     "$name: Option '$OPTARG' requires a value.  Use -h for help."
  159.     exit 1
  160.     ;;
  161.     ?) 
  162.     echo "$name: $OPTARG: bad option.  Use -h for help."
  163.     exit 1
  164.     ;;
  165.     esac
  166. done
  167.  
  168. # remove args that were options
  169. let OPTIND=OPTIND-1
  170. shift $OPTIND
  171.  
  172. [ $# -eq 0 ] && PrintHigh
  173.  
  174. while [ $# -gt 0 ]; do
  175.     case "$1" in
  176.     box) PrintBox;;
  177.     all) PrintAll;;
  178.     high) PrintHigh;;
  179.     *) print -u2 "$Usage"
  180.     exit 1;;
  181.     esac
  182.     shift
  183. done
  184.